﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Geometry;

namespace TestGeometry {
    public class TestPoint {

        public void run() {
            testPlus();
            testMinus();
            testMultiple();
            testDiv();
            testDistance();
            testSquare();
        }

        public void testPlus() {
            Point p = new Point(1.0f, 2.0f, 3.0f);
            Point q = new Point(3.0f, 2.0f, 1.0f);
            Point r = p + q;
            Util.assertEquals(r.x, 4.0f);
            Util.assertEquals(r.y, 4.0f);
            Util.assertEquals(r.z, 4.0f);
        }
        public void testMinus() {
            Point p = new Point(-1.0f, -1.0f, -1.0f);
            Point q = new Point(1.0f, 1.0f, 1.0f);
            Point r = p + q;
            Util.assertEquals(r.x, 0.0f);
            Util.assertEquals(r.y, 0.0f);
            Util.assertEquals(r.z, 0.0f);
        }
        public void testMultiple() {
            Point p = new Point(1.0f, 1.0f, 1.0f);
            float amp = 10.0f;
            Point q = p * amp;
            Point r = amp * p;
            Util.assertEquals(q.x, amp);
            Util.assertEquals(q.y, amp);
            Util.assertEquals(q.z, amp);
            Util.assertEquals(q.x, r.x);
            Util.assertEquals(q.y, r.y);
            Util.assertEquals(q.z, r.z);
        }
        public void testDiv() {
            float amp = 10.0f;
            Point p = new Point(amp, amp, amp);
            Point q = p / amp;
            Util.assertEquals(q.x, 1.0f);
            Util.assertEquals(q.y, 1.0f);
            Util.assertEquals(q.z, 1.0f);
        }
        public void testDistance() {
            Point p = new Point(1.0f, 2.0f, 3.0f);
            Point q = new Point(-1.0f, -2.0f, -3.0f);
            Point e = new Point(0.0f, 0.0f, 0.0f);
            Util.assertEquals(p.distance(e), (float)Math.Sqrt(1.0f + 4.0f + 9.0f));
            Util.assertEquals(p.distance(e), q.distance(e));
        }
        public void testSquare() {
            Point p = new Point(1.0f, 2.0f, 3.0f);
            Point e = new Point(0.0f, 0.0f, 0.0f);
            Util.assertEquals(p.distance(e) * p.distance(e), p.square(e));
        }
    }
}
